import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate"; //Vuex持久化存储配置
Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    LOADING: false,
    token: "",
    userMsg: "",
  },
  mutations: {
    showLoading(state) {
      state.LOADING = true;
    },
    hideLoading(state) {
      state.LOADING = false;
    },
    setLoginMsg(state, val) {
      state.token = val.token;
      state.userMsg = val.userMsg;
    },
  },
  plugins: [
    createPersistedState({
      storage: window.sessionStorage,
      reducer: (state) => ({
        token: state.token,
        userMsg: state.userMsg,
      }),
    }),
  ],
});
export default store;
